/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BarGraphPanelTest.java
 *
 * Created on Aug 3, 2009, 9:21:05 PM
 */
package GraphPackage;

import java.awt.Dimension;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Vector;

/**
 *
 * @author Heather
 */
public class CCPVGraphPanelTest extends javax.swing.JApplet
{

  private Vector<CCPVGraphMember> generateMembers()
  {
    Vector<CCPVGraphMember> ret = new Vector<CCPVGraphMember>();

    for (int i = 0; i < 10; i++)
    {
      int a = randGen.nextInt(4);
      int b = randGen.nextInt(4);
      int c = randGen.nextInt(4);
      int d = randGen.nextInt(4);
      int[] group =
      {
        a, b, c, d
      };

      CCPVGraphMember member = new CCPVGraphMember(group);
      member.name = "group: " + i;
      member.valueType = CCPVGraphMember.ValueTypes.group;

      ret.add(member);
    }

    return ret;
  }

  private HashMap<CCPVGraphMember, Double> generateValues(Vector<CCPVGraphMember> members)
  {
    HashMap<CCPVGraphMember, Double> ret = new HashMap<CCPVGraphMember, Double>();

    for (CCPVGraphMember member : members)
    {
      double input = randGen.nextDouble();
      if (randGen.nextBoolean())
        input *= -1;
      ret.put(member, input);
    }

    return ret;
  }

  /** Initializes the applet BarGraphPanelTest */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          initComponents();
          testContainer.setSize(1000, 1000);
          Vector<CCPVGraphMember> members = generateMembers();
          HashMap<CCPVGraphMember, Double> values = generateValues(members);
          List<List<String>> newNames = new Vector<List<String>>();
          for (CCPVGraphMember member : members)
          {
            Vector<String> newName = new Vector<String>();
            String group = member.name;
            String value = "" + values.get(member);
            newName.add(group);
            newName.add(value);
            newNames.add(newName);
          }
          
          bgp = new CCPVGraphPanel(CCPVGraphPanel.GraphTypes.vertical, members, 1, 0, 0.1);
          bgp.setupBarValues(values);
          bgp.setBarNames(newNames);
          bgp.setSize(defaultSize);
          bgp.setPreferredSize(defaultSize);
          bgp.setLocation(0, 0);
          testContainer.add(bgp);
          repaint();
        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    testContainer = new javax.swing.JPanel();

    testContainer.setBackground(new java.awt.Color(204, 204, 255));
    testContainer.setLayout(null);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(testContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 1044, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(testContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel testContainer;
  // End of variables declaration//GEN-END:variables
  private CCPVGraphPanel bgp;
  private Dimension defaultSize = new Dimension(1000, 1000);
  private Random randGen = new Random();
}
